package com.example.myfinalhomework;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class Change extends AppCompatActivity {
    private static final String TAG = "cc";
    TextView cname,cphone,cbz;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.change);
        Intent intent=getIntent();
        String na=intent.getStringExtra("name");
        userrelated oo = TXmanager.getByName(na);
        Log.i(TAG,"1");

        cname=findViewById(R.id.cname);
        cphone=findViewById(R.id.cphone);
        cbz=findViewById(R.id.cbz);

        cname.setText(oo.getName());
        cphone.setText(oo.getNum());
        cbz.setText(oo.getRemark());

        Button up =findViewById(R.id.cbutton);
        up.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG,"2");
                String namee=cname.getText().toString().trim();
                String phonee=cphone.getText().toString().trim();
                String bze=cbz.getText().toString().trim();

                if(namee.isEmpty()){
                    Toast.makeText(Change.this, "你还没写名字", Toast.LENGTH_SHORT).show();
                }else if(phonee.isEmpty()){
                    Toast.makeText(Change.this, "你的手机号呢", Toast.LENGTH_SHORT).show();
                }else{
                    TXmanager.update(namee,phonee,bze);
                    Toast.makeText(Change.this, "成功辣", Toast.LENGTH_SHORT).show();
                }

            }
        });
        Toolbar toolbar=findViewById(R.id.toolbar_up);
        this.setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG,"4");
                Intent intent1=new Intent(Change.this, Main.class);
                startActivity(intent1);
            }
        });




    }
}